//========================================================================
// This file was generated using the MyGeneration tool in combination
// with the Gentle.NET Business Entity template, $Rev: 1104 $
//========================================================================
using System;
using System.Collections;
using Gentle.Common;
using Gentle.Framework;

namespace GrewalCRM.Entities
{
	/// <summary>
	/// Instances of this class represent the properties and methods of a row in the table <b>Calls</b>.
	/// </summary>
	[TableName("Calls", CacheStrategy.Temporary)]
	public class Calls : BaseEntitiesGrewalCRM
	{
		#region Members
		private bool isChanged;
		private int callID;
		private string callNo;
		private DateTime callReceiveDate;
		private int callTypeID;
		private int dealerID;
		private int customerID;
		private DateTime callBookedDate;
		private int installerID;
		private DateTime callAssignedDate;
		private DateTime callCompletedDate;
		private string remarks;
		private int callStatusID;
		private string aCBrand;
		private DateTime aCParchasedDate;
		private string aCModel;
		private string aCSerialNo;
		private int lastModifiedUser;
		private DateTime lastModifiedDateTime;
		#endregion
			
		#region Constructors
		/// <summary>
		/// Create a new instance using the default constructor
		/// </summary>
		public Calls()
		{
			isChanged = true;
		}

		/// <summary> 
		/// Create a new object using the minimum required information (all not-null fields except 
		/// auto-generated primary keys). 
		/// </summary> 
		public Calls(string callNo, DateTime callReceiveDate, int callTypeID, int dealerID, int customerID, string aCBrand, DateTime aCParchasedDate, string aCModel, string aCSerialNo, int lastModifiedUser, DateTime lastModifiedDateTime)
		{
			isChanged = true;
			callID = 0;
			this.callNo = callNo;
			this.callReceiveDate = callReceiveDate;
			this.callTypeID = callTypeID;
			this.dealerID = dealerID;
			this.customerID = customerID;
			this.aCBrand = aCBrand;
			this.aCParchasedDate = aCParchasedDate;
			this.aCModel = aCModel;
			this.aCSerialNo = aCSerialNo;
			this.lastModifiedUser = lastModifiedUser;
			this.lastModifiedDateTime = lastModifiedDateTime;
		}

		/// <summary> 
		/// Create a new object by specifying all fields (except the auto-generated primary key field). 
		/// </summary> 
		public Calls(string callNo, DateTime callReceiveDate, int callTypeID, int dealerID, int customerID, DateTime callBookedDate, int installerID, DateTime callAssignedDate, DateTime callCompletedDate, string remarks, int callStatusID, string aCBrand, DateTime aCParchasedDate, string aCModel, string aCSerialNo, int lastModifiedUser, DateTime lastModifiedDateTime)
		{
			isChanged = true;
			this.callNo = callNo;
			this.callReceiveDate = callReceiveDate;
			this.callTypeID = callTypeID;
			this.dealerID = dealerID;
			this.customerID = customerID;
			this.callBookedDate = callBookedDate;
			this.installerID = installerID;
			this.callAssignedDate = callAssignedDate;
			this.callCompletedDate = callCompletedDate;
			this.remarks = remarks;
			this.callStatusID = callStatusID;
			this.aCBrand = aCBrand;
			this.aCParchasedDate = aCParchasedDate;
			this.aCModel = aCModel;
			this.aCSerialNo = aCSerialNo;
			this.lastModifiedUser = lastModifiedUser;
			this.lastModifiedDateTime = lastModifiedDateTime;
		}
			
		/// <summary> 
		/// Create an object from an existing row of data. This will be used by Gentle to 
		/// construct objects from retrieved rows. 
		/// </summary> 
		public Calls(int callID, string callNo, DateTime callReceiveDate, int callTypeID, int dealerID, int customerID, DateTime callBookedDate, int installerID, DateTime callAssignedDate, DateTime callCompletedDate, string remarks, int callStatusID, string aCBrand, DateTime aCParchasedDate, string aCModel, string aCSerialNo, int lastModifiedUser, DateTime lastModifiedDateTime)
		{
			this.callID = callID;
			this.callNo = callNo;
			this.callReceiveDate = callReceiveDate;
			this.callTypeID = callTypeID;
			this.dealerID = dealerID;
			this.customerID = customerID;
			this.callBookedDate = callBookedDate;
			this.installerID = installerID;
			this.callAssignedDate = callAssignedDate;
			this.callCompletedDate = callCompletedDate;
			this.remarks = remarks;
			this.callStatusID = callStatusID;
			this.aCBrand = aCBrand;
			this.aCParchasedDate = aCParchasedDate;
			this.aCModel = aCModel;
			this.aCSerialNo = aCSerialNo;
			this.lastModifiedUser = lastModifiedUser;
			this.lastModifiedDateTime = lastModifiedDateTime;
		}
		#endregion

		#region Public Properties
		/// <summary>
		/// Indicates whether the entity is changed and requires saving or not.
		/// </summary>
		public bool IsChanged
		{
			get { return isChanged; }
		}

		/// <summary>
		/// Property relating to database column CallID
		/// </summary>
		[TableColumn("CallID", NotNull=true), PrimaryKey(AutoGenerated=true)]
		public int CallID
		{
			get { return callID; }
			set { isChanged |= callID != value; callID = value; }
		}

		/// <summary>
		/// Property relating to database column CallNo
		/// </summary>
		[TableColumn("CallNo", NotNull=true)]
		public string CallNo
		{
			get { return callNo.TrimEnd(); }
			set { isChanged |= callNo != value; callNo = value; }
		}

		/// <summary>
		/// Property relating to database column CallReceiveDate
		/// </summary>
		[TableColumn("CallReceiveDate", NotNull=true)]
		public DateTime CallReceiveDate
		{
			get { return callReceiveDate; }
			set { isChanged |= callReceiveDate != value; callReceiveDate = value; }
		}

		/// <summary>
		/// Property relating to database column CallTypeID
		/// </summary>
		[TableColumn("CallTypeID", NotNull=true)]
		public int CallTypeID
		{
			get { return callTypeID; }
			set { isChanged |= callTypeID != value; callTypeID = value; }
		}

		/// <summary>
		/// Property relating to database column DealerID
		/// </summary>
		[TableColumn("DealerID", NotNull=true)]
		public int DealerID
		{
			get { return dealerID; }
			set { isChanged |= dealerID != value; dealerID = value; }
		}

		/// <summary>
		/// Property relating to database column CustomerID
		/// </summary>
		[TableColumn("CustomerID", NotNull=true)]
		public int CustomerID
		{
			get { return customerID; }
			set { isChanged |= customerID != value; customerID = value; }
		}

		/// <summary>
		/// Property relating to database column CallBookedDate
		/// </summary>
		[TableColumn("CallBookedDate")]
		public DateTime CallBookedDate
		{
			get { return callBookedDate; }
			set { isChanged |= callBookedDate != value; callBookedDate = value; }
		}

		/// <summary>
		/// Property relating to database column InstallerID
		/// </summary>
		[TableColumn("InstallerID", NullValue=0)]
		public int InstallerID
		{
			get { return installerID; }
			set { isChanged |= installerID != value; installerID = value; }
		}

		/// <summary>
		/// Property relating to database column CallAssignedDate
		/// </summary>
		[TableColumn("CallAssignedDate")]
		public DateTime CallAssignedDate
		{
			get { return callAssignedDate; }
			set { isChanged |= callAssignedDate != value; callAssignedDate = value; }
		}

		/// <summary>
		/// Property relating to database column CallCompletedDate
		/// </summary>
		[TableColumn("CallCompletedDate")]
		public DateTime CallCompletedDate
		{
			get { return callCompletedDate; }
			set { isChanged |= callCompletedDate != value; callCompletedDate = value; }
		}

		/// <summary>
		/// Property relating to database column Remarks
		/// </summary>
		[TableColumn("Remarks", NullValue="")]
		public string Remarks
		{
			get { return remarks != null ? remarks.TrimEnd() : string.Empty; }
			set { isChanged |= remarks != value; remarks = value; }
		}

		/// <summary>
		/// Property relating to database column CallStatusID
		/// </summary>
		[TableColumn("CallStatusID", NotNull = false, NullValue=0), ForeignKey("Reff_CallType", "CallTypeID")]
		public int CallStatusID
		{
			get { return callStatusID; }
			set { isChanged |= callStatusID != value; callStatusID = value; }
		}

		/// <summary>
		/// Property relating to database column ACBrand
		/// </summary>
		[TableColumn("ACBrand", NotNull=true)]
		public string ACBrand
		{
			get { return aCBrand.TrimEnd(); }
			set { isChanged |= aCBrand != value; aCBrand = value; }
		}

		/// <summary>
		/// Property relating to database column ACParchasedDate
		/// </summary>
		[TableColumn("ACParchasedDate", NotNull=true)]
		public DateTime ACParchasedDate
		{
			get { return aCParchasedDate; }
			set { isChanged |= aCParchasedDate != value; aCParchasedDate = value; }
		}

		/// <summary>
		/// Property relating to database column ACModel
		/// </summary>
		[TableColumn("ACModel", NotNull=true)]
		public string ACModel
		{
			get { return aCModel.TrimEnd(); }
			set { isChanged |= aCModel != value; aCModel = value; }
		}

		/// <summary>
		/// Property relating to database column ACSerialNo
		/// </summary>
		[TableColumn("ACSerialNo", NotNull=true)]
		public string ACSerialNo
		{
			get { return aCSerialNo.TrimEnd(); }
			set { isChanged |= aCSerialNo != value; aCSerialNo = value; }
		}

		/// <summary>
		/// Property relating to database column LastModifiedUser
		/// </summary>
		[TableColumn("LastModifiedUser", NotNull = true), ForeignKey("CRM_Users", "UserID")]
		public int LastModifiedUser
		{
			get { return lastModifiedUser; }
			set { isChanged |= lastModifiedUser != value; lastModifiedUser = value; }
		}

		/// <summary>
		/// Property relating to database column LastModifiedDateTime
		/// </summary>
		[TableColumn("LastModifiedDateTime", NotNull=true)]
		public DateTime LastModifiedDateTime
		{
			get { return lastModifiedDateTime; }
			set { isChanged |= lastModifiedDateTime != value; lastModifiedDateTime = value; }
		}
		#endregion

		#region Storage and Retrieval
	
		/// <summary>
		/// Static method to retrieve all instances that are stored in the database in one call
		/// </summary>
		public static IList ListAll()
		{
			return Broker.RetrieveList(typeof(Calls));
		}

		/// <summary>
		/// Retrieves an entity given it's id.
		/// </summary>
		public static Calls Retrieve(int id)
		{
			Key key = new Key(typeof(Calls), true, "CallID", id);
			return Broker.RetrieveInstance(typeof(Calls), key) as Calls;
		}
		
		/// <summary>
		/// Retrieves an entity given it's id, using Gentle.Framework.Key class.
		/// This allows retrieval based on multi-column keys.
		/// </summary>
		public static Calls Retrieve(Key key)
		{
			return Broker.RetrieveInstance(typeof(Calls), key) as Calls;
		}
		
		/// <summary>
		/// Persists the entity if it was never persisted or was changed.
		/// </summary>
		public override void Persist()
		{
			if (IsChanged || !IsPersisted)
			{
				base.Persist();
				isChanged = false;
			}
		}

		#endregion


		#region Relations
		/// <summary>
		///
		/// </summary>
	
		public CRMUsers ReferencedCRMUsersLastModifiedUser()
		{
			return CRMUsers.Retrieve(LastModifiedUser);
		}
		/// <summary>
		///
		/// </summary>
	
		public CRMUsers ReferencedCRMUsersLastModifiedUser()
		{
			return CRMUsers.Retrieve(LastModifiedUser);
		}
		/// <summary>
		///
		/// </summary>
	
		public CRMUsers ReferencedCRMUsersLastModifiedUser()
		{
			return CRMUsers.Retrieve(LastModifiedUser);
		}
		/// <summary>
		///
		/// </summary>
	
		public CRMUsers ReferencedCRMUsersLastModifiedUser()
		{
			return CRMUsers.Retrieve(LastModifiedUser);
		}
		/// <summary>
		///
		/// </summary>
				
		public ReffCallType ReferencedReffCallType()
		{
			return ReffCallType.Retrieve(CallStatusID);
		}
		/// <summary>
		///
		/// </summary>
				
		public ReffStatus ReferencedReffStatus()
		{
			return ReffStatus.Retrieve(CallStatusID);
		}
		#endregion
	}
}
